import java.util.ArrayList;
import java.util.Comparator;
import java.util.HashMap;
import java.util.function.BiConsumer;
import java.util.function.Consumer;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: dings
 * Date: 2024-07-27
 * Time: 11:55
 */
public class LambdaTest2 {
    public static void main(String[] args) {
        HashMap<String,Integer> map = new HashMap<>();
        map.put("hello",10);
        map.put("world",13);
        map.put("abc",20);
        map.forEach(new BiConsumer<String, Integer>() {
            @Override
            public void accept(String s, Integer integer) {
                System.out.println(s+" "+integer+" ");
            }
        });
        //Lambda形式
        map.forEach((key,value) -> System.out.println(key+" "+value+" "));
    }
    public static void main2(String[] args) {
        ArrayList<Integer> list = new ArrayList<>();
        list.add(23);
        list.add(29);
        list.add(13);
        //原匿名内部类排序形式
        /*list.sort(new Comparator<Integer>() {
            @Override
            public int compare(Integer o1, Integer o2) {
                return o1.compareTo(o2);
            }
        });*/
        //Lambda形式 ->排序
        list.sort((o1, o2) -> o1.compareTo(o2));
        //Lambda形式 ->forEach循环
        list.forEach(integer -> System.out.print(integer+" "));
    }
    public static void main1(String[] args) {
        ArrayList<Integer> list = new ArrayList<>();
        list.add(23);
        list.add(29);
        list.add(13);

        //原形式
        list.forEach(new Consumer<Integer>() {
            @Override
            public void accept(Integer integer) {
                System.out.print(integer+" ");
            }
        });
        System.out.println();
        //Lambda形式
        list.forEach(integer -> System.out.print(integer+" "));
    }
}
